import { Injectable, ComponentFactoryResolver, Injector, ApplicationRef } from '@angular/core';
import { TemplateLayoutComponent } from './template-layout/template-layout.component';

@Injectable({
  providedIn: 'root'
})
export class ZeprideTemplateRenderService {

  constructor(
    private resolver: ComponentFactoryResolver,
    private injector: Injector,
    private app: ApplicationRef
  ) { }

  renderTemplateToDom(dom: HTMLElement) {
    const factory = this.resolver.resolveComponentFactory(TemplateLayoutComponent);
    const ref = factory.create(this.injector, [], dom);
    this.app.attachView(ref.hostView);
    return ref;
  }
}
